<template>
  <div class="cu-common-layout">
    <div class="cu-common-layout-center">
      <el-form @submit.native.prevent label-position="right">
        <el-row class="cu-common-search-box support-search-box" :gutter="15">
          <el-col :span="5">
            <el-form-item label="校区品牌" prop="brand">
              <el-select v-model="query.brand" placeholder="">
                <el-option :key="item.id" :label="item.fullName" :value="item.enCode" v-for="item in brandOptions" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="校区信息" prop="info">
              <el-input v-model="query.info" clearable :style="{ width: '100%' }" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="投资人信息" prop="contact">
              <el-input v-model="query.contact" clearable :style="{ width: '100%' }" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="管理区域" prop="company">
              <el-select v-model="query.company" placeholder="">
                <el-option :key="item.id" :label="item.fullName" :value="item.enCode" v-for="item in companyOptions" />
              </el-select>
            </el-form-item>
          </el-col>
          <template v-if="showAll">
            <el-col :span="5">
              <el-form-item label="营业执照主体" prop="businessName">
                <el-input v-model="query.businessName" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="服务截止日期" prop="endDate">
                <el-date-picker v-model="query.endDate" type="daterange" value-format="yyyy-MM-dd" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="开业日期" prop="openDate">
                <el-date-picker v-model="query.openDate" type="daterange" value-format="yyyy-MM-dd" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="校区类型" prop="type">
                <el-select v-model="query.type" placeholder="" clearable>
                  <el-option v-for="item in typeOptions" :key="item.id" :label="item.fullName" :value="item.enCode" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="运营阶段" prop="level">
                <el-select v-model="query.level" placeholder="" clearable>
                  <el-option v-for="item in levelOptions" :key="item.id" :label="item.fullName" :value="item.enCode" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="校区区域" prop="area">
                <custom-address v-model="query.area" :multiple="true" />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="校区状态" prop="status">
                <el-select v-model="query.status" placeholder="" clearable>
                  <el-option v-for="item in statusOptions" :key="item.id" :label="item.fullName" :value="item.enCode" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="参保状态" prop="inurance">
                <el-select v-model="query.inurance" placeholder="请选择参保状态" filterable clearable required :style="{ width: '100%' }">
                  <el-option :key="item.enCode" :label="item.fullName" :value="item.enCode" v-for="item in inuranceOptions" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="保险到期日" prop="inuranceDate">
                <el-date-picker v-model="query.inuranceDate" type="daterange" value-format="yyyy-MM-dd" format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="已开通标签" prop="openTags">
                <el-select v-model="query.openTags" multiple placeholder="请选择" filterable clearable required :style="{ width: '100%' }">
                  <el-option :key="item.enCode" :label="item.fullName" :value="item.enCode" v-for="item in tagsOptions" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="未开通标签" prop="notOpenTags">
                <el-select v-model="query.notOpenTags" multiple placeholder="请选择" filterable clearable required :style="{ width: '100%' }">
                  <el-option :key="item.enCode" :label="item.fullName" :value="item.enCode" v-for="item in tagsOptions" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="生日" prop="birthday">
                <el-date-picker :style="{ width: '100%' }" v-model="query.birthday" value-format="M" format="M月" type="month" placeholder="请选择月份"></el-date-picker>
              </el-form-item>
            </el-col>
          </template>
          <el-col :span="5">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()" native-type="submit">查询</el-button>
              <el-button icon="el-icon-refresh-right" @click="reset()">重置</el-button>
              <el-button type="text" icon="el-icon-arrow-down" @click="showAll = true" v-if="!showAll">展开</el-button>
              <el-button type="text" icon="el-icon-arrow-up" @click="showAll = false" v-else>收起</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="cu-common-layout-main cu-flex-main">
        <div class="cu-common-head">
          <div>
            <el-button type="primary" icon="el-icon-plus" @click="addOrUpdateHandle()" v-has="'btn_add'">新增</el-button>
            <el-button type="text" icon="el-icon-download" @click="exportCampusInfo('zhaoshang')" v-has="'btn_export_zhaoshang'">导出校区信息(招商)</el-button>
            <el-button type="text" icon="el-icon-download" @click="exportCampusInfo('kefu')" v-has="'btn_export_kefu'">导出校区信息(客服)</el-button>
            <el-button type="text" icon="el-icon-download" @click="templateDownload('summarize')" v-has="'btn_export_birthday'">导出生日表</el-button>
          </div>
          <div class="cu-common-head-right">
            <el-tooltip effect="dark" content="刷新" placement="top">
              <el-link icon="icon-ym icon-ym-Refresh cu-common-head-icon" :underline="false" @click="reset()" />
            </el-tooltip>
            <screenfull isContainer />
          </div>
        </div>
        <custom-table v-loading="listLoading" :data="list">
          <el-table-column prop="attributeTags" label="标签" align="center" v-if="custom.hasP('attributeTags')" width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <span @click="handleAttributeTags(scope.row, 'website')" style="cursor: pointer; margin-right: 10px">
                <img class="" src="@/assets/images/tags/g1.png" v-if="scope.row.attributeTags && scope.row.attributeTags.indexOf('website') > -1" style="width: 25px" />
                <img class="" src="@/assets/images/tags/g2.png" v-else style="width: 25px" />
              </span>
              <span @click="handleAttributeTags(scope.row, 'tiktok')" style="cursor: pointer">
                <img class="" src="@/assets/images/tags/d1.png" v-if="scope.row.attributeTags && scope.row.attributeTags.indexOf('tiktok') > -1" style="width: 25px" />
                <img class="" src="@/assets/images/tags/d2.png" v-else style="width: 25px" />
              </span>
            </template>
          </el-table-column>
          <el-table-column label="标签" align="center" v-else width="100" show-overflow-tooltip>
            <template slot-scope="scope">
              <span style="margin-right: 10px">
                <img class="" src="@/assets/images/tags/g1.png" v-if="scope.row.attributeTags && scope.row.attributeTags.indexOf('website') > -1" style="width: 25px" />
                <img class="" src="@/assets/images/tags/g2.png" v-else style="width: 25px" />
              </span>
              <span>
                <img class="" src="@/assets/images/tags/d1.png" v-if="scope.row.attributeTags && scope.row.attributeTags.indexOf('tiktok') > -1" style="width: 25px" />
                <img class="" src="@/assets/images/tags/d2.png" v-else style="width: 25px" />
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="brand" label="校区品牌" align="center" v-if="custom.hasP('brand')" width="80">
            <template slot-scope="scope">
              {{ scope.row.brand | dynamicCodeText(brandOptions) }}
            </template>
          </el-table-column>
          <el-table-column prop="code" label="校区编码" align="center" v-if="custom.hasP('code')" width="80" />
          <el-table-column prop="fullName" label="校区全称" align="left" v-if="custom.hasP('fullName')" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag v-if="scope.row.hasCase" size="mini" :key="scope.row.id" type="danger" effect="dark">
                <template>
                  {{ scope.row.fullName }}
                </template>
              </el-tag>
              <template v-else>
                {{ scope.row.fullName }}
              </template>
            </template>
          </el-table-column>
          <el-table-column prop="shortName" label="校区简称" align="left" v-if="custom.hasP('shortName')" width="180" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag v-if="scope.row.hasCase" size="mini" :key="scope.row.id" type="danger" effect="dark">
                <template>
                  {{ scope.row.shortName }}
                </template>
              </el-tag>
              <template v-else>
                {{ scope.row.shortName }}
              </template>
            </template>
          </el-table-column>
          <el-table-column prop="investors" label="投资人" align="left" v-if="custom.hasP('investors')" width="140" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ formattedInfo(scope.row.investors) }}
            </template>
          </el-table-column>
          <el-table-column prop="fullAddress" label="校区地址" align="left" v-if="custom.hasP('fullAddress')" width="300" show-overflow-tooltip />
          <el-table-column prop="telephone" label="固定电话" align="center" v-if="custom.hasP('telephone')" width="100" show-overflow-tooltip />
          <el-table-column prop="email" label="校区邮箱" align="left" v-if="custom.hasP('email')" width="150" show-overflow-tooltip />
          <el-table-column prop="siteArea" label="租用面积" align="left" v-if="custom.hasP('siteArea')" width="80" />
          <el-table-column prop="usableArea" label="使用面积" align="left" v-if="custom.hasP('usableArea')" width="80" />
          <el-table-column prop="rent" label="场地月租金" align="left" v-if="custom.hasP('rent')" width="80" />
          <el-table-column prop="manager" label="负责人" align="left" v-if="custom.hasP('manager')" width="80" />
          <el-table-column prop="managerMobile" label="联系电话" align="left" v-if="custom.hasP('managerMobile')" width="120" show-overflow-tooltip />
          <el-table-column prop="wechat" label="微信" align="left" v-if="custom.hasP('wechat')" width="120" show-overflow-tooltip />
          <el-table-column prop="type" label="校区类型" align="center" v-if="custom.hasP('type')" width="80">
            <template slot-scope="scope">
              {{ scope.row.type | dynamicCodeText(typeOptions) }}
            </template>
          </el-table-column>
          <el-table-column prop="degreeCount" label="学位数" align="center" v-if="custom.hasP('degreeCount')" width="80" />
          <el-table-column prop="bedCount" label="床位数" align="center" v-if="custom.hasP('bedCount')" width="80" />
          <el-table-column prop="renewal" label="续约费" align="left" v-if="custom.hasP('renewal')" width="80"></el-table-column>
          <el-table-column prop="deposit" label="保证金" align="left" v-if="custom.hasP('deposit')" width="80"></el-table-column>
          <el-table-column prop="status" label="状态" align="center" width="80">
            <template slot-scope="scope">
              <el-tag size="mini" v-if="scope.row.status == 'preparation'" type="" effect="dark">
                筹备
              </el-tag>
              <el-tag size="mini" v-if="scope.row.status == 'normal'" type="success" effect="dark">
                正常
              </el-tag>
              <el-tag size="mini" v-if="scope.row.status == 'expires'" type="info" effect="dark">
                待续费
              </el-tag>
              <el-tag size="mini" v-else-if="scope.row.status == 'suspended'" type="warning" effect="dark">
                暂停
              </el-tag>
              <el-tag size="mini" v-else-if="scope.row.status == 'close'" type="danger" effect="dark">
                闭校
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="level" label="运营阶段" align="left" v-if="custom.hasP('level')" width="80">
            <template slot-scope="scope">
              {{ scope.row.level | dynamicCodeText(levelOptions) }}
            </template>
          </el-table-column>
          <el-table-column prop="openDate" label="开业日期" align="center" v-if="custom.hasP('openDate')" :formatter="custom.tableDateFormat" width="100" />
          <el-table-column prop="startDate" label="服务开始日期" align="center" v-if="custom.hasP('startDate')" :formatter="custom.tableDateFormat" width="100" />
          <el-table-column prop="endDate" label="服务结束日期" align="center" v-if="custom.hasP('endDate')" :formatter="custom.tableDateFormat" width="100" />
          <el-table-column prop="businessName" label="营业执照主体" align="left" v-if="custom.hasP('businessName')" width="200" show-overflow-tooltip />
          <el-table-column label="操作" width="250" align="center" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="addOrUpdateHandle(scope.row.id, false)" v-has="'btn_edit'">编辑</el-button>
              <el-button type="text" size="mini" @click="addOrUpdateHandle(scope.row.id, true)" v-has="'btn_detail'">详细</el-button>
              <el-button type="text" v-has="'btn_edit'" size="mini" @click="onRecordsFormHandle(scope.row.id)">变更</el-button>
              <el-button v-if="scope.row.status != 'normal' || scope.row.status != 'preparation'" type="text" size="mini" v-has="'btn_start'" @click="changeStatusHandle(scope.row.id, 'normal')">启动</el-button>
              <el-button v-if="scope.row.status != 'suspended' || scope.row.status != 'preparation'" type="text" size="mini" v-has="'btn_suspended'" @click="changeStatusHandle(scope.row.id, 'suspended')">暂停</el-button>
              <el-button v-if="scope.row.status != 'close'" type="text" size="mini" v-has="'btn_close'" class="cu-table-delBtn" @click="changeCloseHandle(scope.row, 'close')">闭校</el-button>
              <el-button type="text" size="mini" v-has="'btn_insurance'" @click="recordsHandle(scope.row.id)">参保（{{ scope.row.insurances ? scope.row.insurances.length : 0 }}）</el-button>
              <el-dropdown v-has="'btn_jiaxiao'">
                <span class="el-dropdown-link">
                  <el-button type="text" size="mini">
                    家校平台
                    <i class="el-icon-arrow-down el-icon--right"></i>
                  </el-button>
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item @click.native="handleAsyncJiaXiao(scope.row.id, 'create')">
                    创建帐号
                  </el-dropdown-item>
                  <el-dropdown-item @click.native="handleAsyncJiaXiao(scope.row.id, 'sync')">
                    同步信息
                  </el-dropdown-item>
                  <el-dropdown-item @click.native="handleAsyncJiaXiao(scope.row.id, 'changeAdmin')">
                    更换管理员
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </custom-table>
        <pagination :total="total" :page.sync="listQuery.currentPage" :limit.sync="listQuery.pageSize" @pagination="initData" />
      </div>
    </div>
    <custom-form v-if="formVisible" ref="CustomForm" @refresh="refresh" />
    <close-support-form v-if="closeSupportVisible" ref="CloseSupport" @refresh="search" />
    <status-box v-if="statusVisible" ref="StatusBox" @refresh="refresh" />
    <ExportBox v-if="exportBoxVisible" ref="ExportBox" @download="download" />
    <records-form v-if="recordsVisible" ref="RecordsForm" @refresh="refresh" />
    <records-handle-form v-if="recordsHandleVisible" ref="RecordsHandleForm" @refresh="refresh" type="campus" />
  </div>
</template>
<script>
export { default } from './index.js'
</script>
<style lang="scss" scoped>
@import url(index.scss);
</style>
